﻿package net.sealuitk.containers 
{
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import net.sealuitk.Container;
	import net.sealuitk.UIConst;
	
	/**
	 * ...
	 * @author mkn
	 */
	public class FlowVertical extends Container
	{
		protected var row:Row;
		protected var currentColumn:Column;
		
		public function FlowVertical(Name:String, Width:Number, Height:Number, AlignHorizontal:String = UIConst.ALIGN_LEFT, AlignVertical:String = UIConst.ALIGN_TOP ) {
			super(Name, Width, Height);
			alignVertical = AlignVertical;
			alignHorizontal = AlignHorizontal;
			row = new Row("VFlow Column", Width, Height, alignHorizontal, UIConst.ALIGN_TOP );
			super.add(row);
			nextColumn();
		}
		
		override public function add(newContent:*, floating:Boolean = false ):void {
			if (floating) add(newContent, true);
			else {
				if (sizeSet) {
					if ( ( currentColumn.height + contentPadding.y + newContent.height ) 
						> ( this.height - (padding.top + padding.bottom) ) ) {
						nextColumn();	
					}
				}
				currentColumn.add(newContent);
				currentColumn.update();
				row.update();
				update();
			}
		}
		
		public function nextColumn():void {
			contentFixed.push(new Column("Column " + (contentFixed.length - 1), 0, 0, UIConst.ALIGN_MIDDLE, alignVertical ) );
			currentColumn = contentFixed[ contentFixed.length -1 ];
			currentColumn.setContentPadding(contentPadding.x, contentPadding.y);
			row.add( currentColumn );
		}
		
		override public function setContentPadding(horizontal:Number, vertical:Number):void {
			super.setContentPadding(horizontal, vertical);
			super.updateFixed();
			
			for (var i:int = 0; i < contentFixed.length ; i++) {
				contentFixed[i].setContentPadding(horizontal, vertical);
			}
			
			row.setContentPadding( horizontal , vertical);
		} 
	}

}